package com.sky.service.impl;

import com.sky.constant.StatusConstant;
import com.sky.service.ShopService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class ShopServiceImpl implements ShopService {
    public static final String KEY = "SHOP_STATUS";

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public void setStatus(Integer status) {
        log.info("设置店铺营业状态:{}",status);
        ValueOperations valueOperations = redisTemplate.opsForValue();
        valueOperations.set(KEY,status);
    }

    @Override
    public Integer getStatus() {
        ValueOperations valueOperations = redisTemplate.opsForValue();
        Integer shopStatus =(Integer) valueOperations.get(KEY);
        if (shopStatus == null){
            shopStatus = StatusConstant.DISABLE;
        }
        return shopStatus;
    }
}
